#ifndef IMAGETHUMBSCACHE_H
#define IMAGETHUMBSCACHE_H

#include "ImageFileThumb.h"
#include <QtCore/QMap>
#include "ImagesLoadThread.h"

class ImageThumbsCache :public QObject
{
	Q_OBJECT
public:
	ImageThumbsCache();
	virtual ~ImageThumbsCache();

	void load(const QString& absDirPath);
	void save() const;

	void startRefreshing();
	void stopRefreshing();

	void setThumbsSize(const QSize&) ;
	QImage   image(const QString& fileName) ;

	void clear();

	void notifyFileRenamed(const QString& name,const QString& newName);
signals:
	void imageChanged(const QString& fileName);
private:
	ImageFileThumb*  findThumb(const QString& fileName) ;
	ImageFileThumb*  createThumb(const QString& fileName,const QSize& size);

private:
	QSize   _thumbsSize;
	QString _currAbsDirPath;
	typedef QMap<QString,ImageFileThumb*>	ImageFileThumbs;
	ImageFileThumbs  _imageFileThumbs;

	ImagesLoadThread _imageLoader;

	mutable bool _isModified;
private slots:
	void onImageLoaded(const QImage& image,const QString& filePath);
};

#endif // IMAGETHUMBSCACHE_H
